Skip to main content

Publishing over UDP Bridge

This section explains how devices can use the UDP bridge to communicate with Omnicore. For general information about TCP and UDP, see Protocols.

Be sure to refer to the API documentation for full details about each method described in this section. See also the UDP-related samples.

To publish over the UDP bridge:

  1. Install an UDP client on your device.

  2. Initiate a UDP connection over hostprefix.udp.korewireless.com or a long-term support domain.

  3. Publish telemetry events.

UDP server

Omnicore supports the UDP protocol by running a managed broker that listens to the port hostprefix.udp.korewireless.com: port. port is available in the device connection info which is reserved with IANA for secure UDP connections.

note

The UDP standard is defined for implementing a full publish/subscribe broker. However, the managed UDP bridge run by Omnicore does not support all publish/subscribe operations, such as creating arbitrary topics that devices can use to send messages between them. (Filtering can be accomplished with downstream processes running on Cloud Pub/Sub.) Omnicore uses a predefined set of topics and specific topic formats.

Publishing telemetry events

After the device is configured with an UDP client and connected to the UDP bridge, it can publish a telemetry event by issuing a PUBLISH message to an UDP topic in the following format:

path
 /REGISTRY_ID/DEVICE_ID/events

The device ID is the string ID of the device specified in the UDP client ID. The device ID is case sensitive.

Messages published to this UDP topic are forwarded to the corresponding registry's default telemetry topic. If no default Pub/Sub topic exists, published telemetry data will be lost. To publish messages to other Cloud Pub/Sub topics, see Publishing telemetry events to additional Cloud Pub/Sub topics.

The forwarded message data field contains a copy of the message published by the device, and the following message attributes are added to each message in the Cloud Pub/Sub topic:

AtributeDescription
deviceIdThe user-defined string identifier for the device, for example, thing1. The device ID must be unique within the registry.
deviceNumIdThe server-generated numeric ID of the device. When you create a device, Omnicore automatically generates the device numeric ID; it's globally unique and not editable.
deviceRegistryIdThe user-defined string identifier for the device registry, for example, registry1.
subscriptionIdThe string ID of the subscription that owns the registry and device.

The following sample shows how to send PUBLISH messages through the UDP connection:

PUBLISH messages through the UDP connection
package main

import (
"fmt"
"log"
"net"
"time"
)

func main() {
host := "hostprefix.udp.korewireless.com"
port := "udp_device_port"

// Resolve UDP address
address, err := net.ResolveUDPAddr("udp", host+":"+port)
if err != nil {
log.Fatalf("[main] Failed to resolve UDP address: %v", err)
}

// Dial UDP connection
conn, err := net.DialUDP("udp", nil, address)
if err != nil {
log.Fatalf("[main] Failed to connect to UDP device: %v", err)
}
defer conn.Close()

// Send data
message := []byte("Hello, UDP device!")
log.Printf("[main] Sending message: %s", message)
_, err = conn.Write(message)
if err != nil {
log.Fatalf("[main] Failed to send message: %v", err)
}

// Receive response
buffer := make([]byte, 1024)
n, _, err := conn.ReadFromUDP(buffer)
if err != nil {
log.Fatalf("[main] Failed to read response: %v", err)
}
response := string(buffer[:n])
log.Printf("[main] Received response: %s", response)

// Close connection
log.Printf("[main] Closing connection")
conn.Close()

log.Println("[main] Done")
}